

********FIRST FIVE COLUMNS********
est clear

use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
drop if missing(five_day_convex_div)
drop if missing(futret_5)

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

*convexity five-day rank
gen convex_five=.
sort monthyear five_day_convex_div
by monthyear: replace convex_five=1 if _n<_N/5
by monthyear: replace convex_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace convex_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace convex_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace convex_five=5 if _n>=_N/5*4

replace futret_5=futret_5*100
replace futexcess_5=futexcess_5*100

egen vw_raw=wtmean(futret_5), weight(mktcap) by(monthyear convex_five)
egen vw_excess=wtmean(futexcess_5),  weight(mktcap) by(monthyear convex_five)

*consolidate to one observation per month
sort convex_five monthyear 
collapse vw_raw vw_excess, by(convex_five monthyear)

tsset convex_five monthyear  

forval i=1/5 {
	eststo: newey vw_raw if convex_five ==`i', lag(6)
}

egen std_vw=sd(vw_excess), by(convex_five)

egen mean_ret_vw=mean(vw_excess), by(convex_five)

gen sharpe_vw=mean_ret_vw/std_vw 

keep convex_five std_vw mean_ret_vw sharpe_vw

duplicates drop
}

tab convex_five, sum(sharpe_vw)


********LAST COLUMN********
use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
drop if missing(five_day_convex_div)
drop if missing(futret_5)

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

*convexity five-day rank
gen convex_five=.
sort monthyear five_day_convex_div
by monthyear: replace convex_five=1 if _n<_N/5
by monthyear: replace convex_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace convex_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace convex_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace convex_five=5 if _n>=_N/5*4

replace futret_5=futret_5*100
replace futexcess_5=futexcess_5*100

egen vw_raw=wtmean(futret_5), weight(mktcap) by(monthyear convex_five)
egen vw_excess=wtmean(futexcess_5),  weight(mktcap) by(monthyear convex_five)

*consolidate to one observation per month
sort convex_five monthyear 
collapse vw_raw vw_excess, by(convex_five monthyear)

tsset convex_five monthyear  

sort  convex_five monthyear

keep if convex_five==1 | convex_five==5

sort monthyear convex_five

gen vw_excess_dif=vw_excess-vw_excess[_n+1] if convex_five==1

keep if convex_five==1

sort  convex_five monthyear

eststo: newey vw_excess_dif , lag(6)

egen std_vw=sd(vw_excess_dif)

egen mean_ret_vw=mean(vw_excess_dif) 

gen sharpe_vw=mean_ret_vw/std_vw 
}

tab convex_five, sum(sharpe_vw)

esttab using "$jfqa_rep/Table_IA3C.csv", nostar replace b(2)
